package cli.menu;

/**
 * BudgetBuoy
 * 
 * Simplify your personal expense management
 * 
 * @team cs2103jan13-w15-3j
 */

//--------------------------------------------------------------

/**
 * AddEntryMenu Class
 * 
 * Description: 
 * 
 * 
 * @package   cli.menu
 * @author    Lai Yong Quan (A0080909Y)
 * 
 */




class AddEntryMenu extends Function{

	private static final String[] ADDENTRYMENU = {
		"-= Main menu > Add Entry =-",
		"[b]: back [u]: undo [r]: redo [h]: home menu",
		"Select type of entry:",
		"1. Expense",
		"2. Expense with receipt (not as of V0.1)",
		"3. Loan Payments",
		"4. Income",
		"5. Cash Loan",
		"",
		"Option: ",
	};

	private static final State BACK = State.MAINMENU;
	private static final State CURRENT = State.ADDENTRYMENU;

	public static State runMenu(){
	
		String input = null;
		
		while(input == null || input.length() == 0){
		cli.print(ADDENTRYMENU);
		input = cli.nextLine();
		cli.clearScreen();
		}

		return processInput(input);

	}

	private static State processInput(String input){

		//full length commands not supported yet (magic word is YET)
		if ((input == null)||(input.length() > 1) || (input.length() == 0))
			return CURRENT;

		State nextState = CURRENT;
		char charInput = input.charAt(0);

		if (input.length() == 1)
			switch (charInput) {
			case 'b':
			case 'B':
				nextState = BACK;
				break;
			case 'u':
			case 'U':
				tools.undo();
				break;
			case 'r':
			case 'R':
				tools.redo();
				break;
			case 'h':
			case'H':
				nextState = State.MAINMENU;
				break;
			case '1':
				nextState = State.ADDEXPENSE;
				break;
			case '2':
				nextState = State.ADDRECEIPT;
				break;
			case '3':
				nextState = State.ADDLOANPAYMENT;
				break;
			case '4':
				nextState = State.ADDINCOME;
				break;
			case '5':
				nextState = State.ADDCASHLOAN;
				break;

			default: {
				// if invalid input
				cli.println("Invalid input received: " + input);
			}

			}
		return nextState;


	}

}